<?php
/**
 * Created by PhpStorm.
 * Date: 2021/11/20
 * Time: 14:12
 */

namespace ApiSdk\SmallRedBook\Servers\Common;


use ApiSdk\SmallRedBook\Servers\Request\SmallRedBookBaseRequest;

/**
 * 小红书公共类
 * @package App\Servers\SmallRedBook\Common
 */
class SmallRedBookCommon extends SmallRedBookBaseRequest
{

    /**
     * 物流地址redis缓存key
     * @var string
     */
    public $cacheExpressListKey="logistics-smallredbook-expresslist-key";

    /**
     * 获取分类列表
     * author: Linqh
     * Date  2021/11/20 16:54
     * @param string $categoryId 父级分类,如果该参数为空，则返回所有的一级分类
     * @return mixed
     */
    public function getCategories($categoryId = '')
    {
        $this->setCommonParam('common.getCategories');
        $this->addParam('categoryId', $categoryId);
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }

    /**
     * 由末级分类获取规格
     * author: Linqh
     * Date  2021/11/20 16:54
     * @param string $categoryId 末级分类ID
     * @return mixed
     */
    public function getVariations(string $categoryId = '')
    {
        $this->setCommonParam('common.getVariations');
        $this->addParam('categoryId', $categoryId);
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }

    /**
     * 由末级分类获取属性
     * author: Linqh
     * Date  2021/11/20 17:16
     * @param string $categoryId 末级分类ID
     * @return mixed
     */
    public function getAttributeLists(string $categoryId = '')
    {
        $this->setCommonParam('common.getAttributeLists');
        $this->addParam('categoryId', $categoryId);
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }

    /**
     * 由属性获取属性值
     * author: Linqh
     * Date  2021/11/20 17:16
     * @param string $attributeId 属性值编号
     * @return mixed
     */
    public function getAttributeValues(string $attributeId ='')
    {
        $this->setCommonParam('common.getAttributeValues');
        $this->addParam('attributeId', $attributeId);
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }

    /**
     * 获取物流信息列表
     * author: Linqh
     * Date  2021/11/20 17:20
     * @return mixed
     */
    public function getExpressCompanyList()
    {
        $this->setCommonParam('common.getExpressCompanyList');
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        //写入缓存
        if(\Cache::has($this->cacheExpressListKey)) {
            \Cache::forget($this->cacheExpressListKey);
        }
        \Cache::forever($this->cacheExpressListKey,$response['data']);
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }

    /**
     * 获取物流方案列表
     * author: Linqh
     * Date  2021/11/20 17:22
     * @return mixed
     */
    public function getLogisticsList()
    {
        $this->setCommonParam('common.getLogisticsList');
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }

    /**
     * 运费模版列表
     * author: Linqh
     * Date  2021/11/20 17:39
     * @param string $pageIndex 当前页数
     * @param string $pageSize 每页条数
     * @return mixed
     */
    public function getCarriageTemplateList(string $pageIndex, string $pageSize)
    {
        $this->setCommonParam('common.getCarriageTemplateList');
        $this->addParam('pageIndex', $pageIndex);
        $this->addParam('pageSize', $pageSize);
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }

    /**
     * 运费模版详情
     * author: Linqh
     * Date  2021/11/20 17:36
     * @param string $templateId 运费模板ID
     * @return mixed
     */
    public function getCarriageTemplate(string $templateId)
    {
        $this->setCommonParam('common.getCarriageTemplate');
        $this->addParam('templateId', $templateId);
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }

    /**
     * 品牌列表
     * author: Linqh
     * Date  2021/11/20 17:44
     * @param string $categoryId 末级类目id
     * @param string $keyword 品牌关键字
     * @param string $pageNo 品牌页数
     * @param string $pageSize 品牌列表每页数量
     * @return mixed
     */
    public function brandSearch(string $categoryId, string $keyword, string $pageNo, string $pageSize)
    {
        $this->setCommonParam('common.brandSearch');
        $this->addParam('categoryId', $categoryId);
        $this->addParam('keyword', $keyword);
        $this->addParam('pageNo', $pageNo);
        $this->addParam('pageSize', $pageSize);
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }

    /**
     * 获取物流模式列表
     * author: Linqh
     * Date  2021/11/20 17:45
     * @return mixed
     */
    public function logisticsMode()
    {
        $this->setCommonParam('common.logisticsMode');
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }

    /**
     * 获取地址信息
     * author: Linqh
     * Date  2021/11/20 17:48
     */
    public function getNestZone()
    {
        $this->setCommonParam('common.getNestZone');
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }

    /**
     * 获取老版本商家授权信息
     * author: Linqh
     * Date  2021/11/20 17:48
     * @return mixed
     */
    public function getSellerKeyInfo()
    {
        $this->setCommonParam('common.getSellerKeyInfo');
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }

}
